package com.group.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.group.pojo.TbMenu;
import com.group.pojo.TbRoleMenu;
import com.group.service.RoleMenuService;

/**
 * 权限管理
 * @author caoyanan
 * @time 2017年11月20日上午10:27:41
 */
@Controller
@RequestMapping("/roleMenu")
public class RoleMenuController {

	@Autowired 
	private RoleMenuService roleMenuService;
	
	@RequestMapping("/page.action")
	public String role() {
		return "admin/role-menu";
	}
	
	@RequestMapping("/save.action")
	@ResponseBody
	public Map<String, String> save(@RequestBody List<TbRoleMenu> roleMenus, HttpServletRequest request) {
		Map<String, String> map = roleMenuService.save(roleMenus, request);
		return map;
	}
	
	@RequestMapping("/query.action")
	@ResponseBody
	public List<TbRoleMenu> query(TbRoleMenu roleMenu) {
		List<TbRoleMenu> list = roleMenuService.query(roleMenu);
		return list;
	}
	
	@RequestMapping("/clearRoleMenu.action")
	@ResponseBody
	public String clearRoleMenu(TbRoleMenu roleMenu) {
		String result = roleMenuService.clearRoleMenu(roleMenu);
		return result;
	}
	
	@RequestMapping("/getUserMenuTreeByUserId.action")
	@ResponseBody
	public List<TbMenu> getUserMenuTreeByUserId(String userId) {
		List<TbMenu> userRoleMenus = roleMenuService.getUserMenuTreeByUserId(userId);
		return userRoleMenus;
	}
}